home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Magazine / WiredWorld / THOR_2.5 / THOR_2.5a_upgrade / rexx / bbsread / DelDupes.br < prev    next >
Text File  |  1997-09-15  |  6KB  |  185 lines

  1. /*
  2. ** $VER: DelDupes.br 1.5 (4.9.97)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** This script will delete duplicate entries in the file database. The first
  6. ** occurence of each filename will be kept, subsequent occurences IN ANY FILE
  7. ** AREA will be deleted. (currently, I'll do something about this later)
  8. **
  9. **
  10. ** Usage:   DelDupes.br SYSTEM/M,ALL/S,USEEXCLUDES/S,PURGE/S,QUIET/S
  11. **
  12. ** Args:    SYSTEM      The name of the system you want to check. Multiple
  13. **                      systems can be specified
  14. **          ALL         Check dupes on all systems
  15. **          USEEXCLUDE  Delete file areas in SortMail's exclude file
  16. **                      See SortMail.guide -> Actions Cfg -> Aminet
  17. **          PURGE       Perform file database maintainance afterwards
  18. **          QUIET       Don't display any progress information
  19. **
  20. ** Example: DelDupes.br "Ygdrasil" "Ultima Thule" PURGE
  21. **
  22. **
  23. ** New for 1.4:
  24. **  o USEEXCLUDES command line switch
  25. **
  26. ** New for 1.50:
  27. **  o Version numbering will from now on follow the C= guidelines
  28. **
  29. ** Ideas:
  30. **  o GUI interface if run from Thor
  31. **  o Allow identical filenames across file areas
  32. **
  33. */
  34.  
  35. options results
  36.  
  37. signal on break_c
  38. signal on halt
  39.  
  40. trace off
  41.  
  42. parse arg arguments
  43.  
  44. /* Find BBSREAD ARexx ports' */
  45.  
  46. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  47.  
  48. /* Parse command line arguments */
  49.  
  50. template = 'SYSTEM/M,ALL/S,GLOBAL/S,USEEXCLUDES/S,PURGE/S,QUIET/S'
  51.  
  52. if arguments = '' then do
  53.     say 'Template: 'template
  54.     say 'Show the script in a text viewer for more information.'
  55.     exit(0)
  56.     end
  57.  
  58. address(bbsread)
  59. 'READARGS TEMPLATE 'template' STEM 'args' CMDLINE 'arguments
  60. if rc ~= 0 then do
  61.     say BBSREAD.LASTERROR
  62.     say 'Template: 'template
  63.     say 'Show the script in a text viewer for more information.'
  64.     exit(0)
  65.     end
  66.  
  67. if (symbol('args.SYSTEM.COUNT') = 'VAR') & (args.ALL) then do
  68.     say 'You must specify either one or more system names or ALL.'
  69.     say 'Template: 'template
  70.     say 'Show the script in a text viewer for more information.'
  71.     exit(0)
  72.     end
  73.  
  74. if (args.ALL) then GETBBSLIST args.SYSTEM
  75.  
  76. FDF_DELETED = '00000001'x
  77.  
  78. totchecked = 0; dupes = 0; 
  79.  
  80. do h = 1 to args.SYSTEM.COUNT
  81.  
  82.     /* Initialize variables */
  83.  
  84.     checked = 0; dupeshere = 0; adel = 0
  85.  
  86.     address(bbsread)
  87.     'GETBBSDATA "'args.SYSTEM.h'" 'sysdata
  88.     if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  89.     if (right(sysdata.BBSPATH, 1) ~= ':') & (right(sysdata.BBSPATH, 1) ~= '/') then sysdata.BBSPATH = sysdata.BBSPATH || '/'
  90.  
  91.     /*
  92.     ** Read SortMail's exclude file
  93.     */
  94.  
  95.     if (args.USEEXCLUDES) & (exists(sysdata.BBSPATH || 'SortMail.excl')) then do
  96.         openexcl = open(ef, sysdata.BBSPATH || 'SortMail.excl', 'R')
  97.         if (openexcl) then do
  98.             cnt = 0
  99.             do until eof(ef)
  100.                 entry = readln(ef)
  101.                 if (entry ~= '') then do; cnt = cnt + 1; excldir.cnt = entry; end
  102.                 end
  103.             excldir.count = cnt
  104.             call close(ef)
  105.             end
  106.         else say 'Could not open SortMail''s exclude file.'
  107.         end
  108.  
  109.     /* Start the work... */
  110.  
  111.     'GETFAREALIST BBSNAME "'args.SYSTEM.h'" STEM 'fareas
  112.     if (rc ~= 0) then do; say BBSREAD.LASTERROR; exit(0); end
  113.  
  114.     if fareas.COUNT = 0 then do
  115.         say 'No file areas on this system.'
  116.         exit(0)
  117.         end
  118.  
  119.     if ~args.QUIET then say '1B'x'[4mChecking for dupes on "'args.SYSTEM.h'" - 'fareas.COUNT' file areas.' || '1B'x'[0m' || '1B'x'[1B'
  120.  
  121.     do i = 1 to fareas.COUNT
  122.         drop fadata.
  123.         'GETFAREADATA BBSNAME "'args.SYSTEM.h'" FAREANAME "'fareas.i'" STEM 'fadata
  124.         if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  125.  
  126.         if ~args.QUIET then do
  127.             say '1B'x'[1A' || '1B'x'[K' || '1B'x'[1m'fareas.i || '1B'x'[0m'
  128.             say '1B'x'[1A' || '1B'x'[20Ccontains 'fadata.NUMFILES' files.'
  129.             say '1B'x'[1A' || '1B'x'[42C' || '1B'x'[3mProcessing...' || '1B'x'[0m' || '1B'x'[1B'
  130.             end
  131.  
  132.         if (symbol('excldir.count') = 'VAR') then do j = 1 to excldir.count
  133.             if ((index(excldir.j, '/') > 0) & (fareas.i = excldir.j)) | (left(fareas.i, length(excldir.j)) = excldir.j) then do
  134.                 if ~(args.QUIET) then say '1B'x'[2A' || '1B'x'[42C' || '1B'x'[3mDeleting...' || '1B'x'[0m' || '1B'x'[1B'
  135.                 'CONFIGFAREA "'args.SYSTEM.h'" "'fareas.i'" DELETEFAREA'
  136.                 if (rc ~= 0) then do; say BBSREAD.LASTERROR; exit(0); end
  137.                 if ~(args.QUIET) then say '1B'x'[2A' || '1B'x'[42C' || '1B'x'[0mArea deleted.' || '1B'x'[0m' || '1B'x'[1B'
  138.                 adel = adel + 1
  139.                 iterate i
  140.                 end
  141.             end
  142.  
  143.         thisfile = fadata.FIRSTFILE
  144.  
  145.         if fadata.NUMFILES > 0 then do until checked = fadata.NUMFILES
  146.             drop filetags. filedata. found.
  147.             'READBRFILE BBSNAME "'args.SYSTEM.h'" FAREANAME "'fareas.i'" FILENR 'thisfile' TAGSSTEM 'filetags' DATASTEM 'filedata
  148.             if (rc ~= 0) then do; say BBSREAD.LASTERROR; exit(0); end
  149.             nextfile = result
  150.  
  151.             if (bitand(DATA.FLAGS,FDF_DELETED) ~= FDF_DELETED) then do
  152.                 'SEARCHBRFILE BBSNAME "'args.SYSTEM.h'" STEM 'found' SEARCH "'filetags.NAME'" NAME'
  153.                 if (rc ~= 0) then do; say BBSREAD.LASTERROR; exit(0); end
  154.  
  155.                 do j = 1 to found.FILEAREA.COUNT
  156.                     do k = 1 to found.FILE.j.COUNT
  157.                         if (found.FILE.j.k ~= thisfile) then do
  158.                             if ~(args.QUIET) then say '1B'x'[1A' || '1B'x'[KDupe: 'found.FILEAREA.j'/'filetags.NAME
  159.                             'WRITEBRFILE BBSNAME "'args.SYSTEM.h'" FAREANAME "'found.FILEAREA.j'" UPDATEFILENR 'found.FILE.j.k' DELETEFILE'
  160.                             if (rc ~= 0) then do; say BBSREAD.LASTERROR; exit(0); end
  161.  
  162.                             if ~(args.QUIET) then say '1B'x'[1A' || '1B'x'[42CDELETED'
  163.                             dupes = dupes + 1; dupeshere = dupeshere + 1
  164.                             end
  165.                         end
  166.                     end
  167.  
  168.                 checked = checked + 1; totchecked = totchecked + 1
  169.                 thisfile = nextfile
  170.                 end
  171.             end
  172.  
  173.         if ~args.QUIET then say '1B'x'[2A' || '1B'x'[42C' || '1B'x'[K'dupeshere' dupes found.' || '1B'x'[1B'
  174.         checked = 0; dupeshere = 0
  175.         end
  176.  
  177.         if args.PURGE & ~args.QUIET then 'PACKDATAFILE "'args.SYSTEM.h'" FILEDATA SHOWPROGRESS'
  178.         if args.PURGE & args.QUIET then 'PACKDATAFILE "'args.SYSTEM.h'" FILEDATA'
  179.         if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  180.     end
  181.  
  182. break_c:
  183. halt:
  184. if ~args.QUIET then say 'Checked 'totchecked' files and found 'dupes' duplicates. 'adel 'file areas were deleted.'
  185.